<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2023/5/4
Time: 12:04
To change this template use File | Settings | File Templates.
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>
    <script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js"></script>
    <title>用户信息查询</title>
    <style type="text/css">
        table {
            border: 2px solid black;
            border-collapse: collapse;
            width: 80%;
            margin: auto;
        }
        th, td {
            border: 1px solid black;
            padding: 10px;
            text-align: center;
        }
        th {
            background-color: lightblue;
        }
        h1, form, input {
            text-align: center;
        }
        button{
            background-color: orange;
        }
        #result{
            position: fixed;
            right: 50px;
        }
    </style>
</head>
<body>
<h1>用户信息</h1>
<% Object userinfo = request.getAttribute("userinfo"); %>
<table>
    <tr>
        <td>用户名</td>
        <td>${userinfo.userAccount}</td>
    </tr>
    <tr>
        <td>年龄</td>
        <td>${userinfo.age}</td>
    </tr>
    <tr>
        <td>性别</td>
        <c:if test="${userinfo.gender==1}">
            <td>女</td>
        </c:if>
        <c:if test="${userinfo.gender==0}">
            <td>男</td>
        </c:if>
    </tr>
    <tr>
        <td>电话</td>
        <td>${userinfo.phone}</td>
    </tr>
    <tr>
        <td>邮箱</td>
        <td>${userinfo.email}</td>
    </tr>

</table>
    <button id="result" type="button" onclick="download()">下载附件</button>


<script>
    function download() {
        var name = "${requestScope.option}";
        console.log(111);
        console.log(name);
        // const name = encodeURIComponent($("#selectName").val());
        $.ajax({
            url: "http://localhost:8080/stadium/common/downLoadQueryUserInfo",
            method: "POST",
            data: {userAccount: name},
            xhrFields: {
                responseType: 'blob'
            },
            success: function (data) {
                var a = document.createElement('a');
                var url = window.URL.createObjectURL(data);
                console.log(url)
                a.href = url;
                a.download = "QueryUserInfo.csv";
                document.body.append(a);
                a.click();
                window.URL.revokeObjectURL(url);
                $(a).remove();
            },
            error: function (jqXHR, textStatus, errorThrown) {
                console.log("Error:", errorThrown);
            }
        });
        console.log("111")
    }

</script>
</body>
</html>
